 <link href="<?= STATICURL; ?>css/bootstrap.min.css" rel="stylesheet" />
    <link id="bootstrap-rtl-link" href="" rel="stylesheet" />
    <link href="<?= STATICURL; ?>css/font-awesome.min.css" rel="stylesheet" />
    <!--Fonts-->
    <!--Beyond styles-->
    <link id="beyond-link" href="<?= STATICURL; ?>css/beyond.min.css" rel="stylesheet" type="text/css" />
    <link id="skin-link" href="" rel="stylesheet" type="text/css" />
    <div class="page-content">
        <div class="page-body">
            <div id="horizontal-form">
                    <form class="form-horizontal" role="form">
                        <div class="row">
                            <div class="col-md-7 pull-left">
								<div >题型：</div>
                                <select class="questionType">
                                    <option <?php if($questionInfo['questionType'] == 1):?>selected="selected"<?php endif?>  value="1">单选</option>
                                    <option <?php if($questionInfo['questionType'] == 2):?>selected="selected"<?php endif?> value="2">填空</option>
                                    <option <?php if($questionInfo['questionType'] == 3):?>selected="selected"<?php endif?> value="3">选图</option>
                                </select>
                            </div>
							<div class="col-md-3 pull-left">
							单题得积分：
                                <input class="form-control single_question_point" value="<?=$questionInfo['single_question_point']?>" type="text" placeholder="请输入得积分">
                                <div class="horizontal-space"></div>
                            </div>
                            <div class="col-md-3 pull-left">
                            单题得奖金：
                                <input class="form-control single_question_money" value="<?=$questionInfo['single_question_money']?>" type="text" placeholder="请输入得奖金">
                                <div class="horizontal-space"></div>
                            </div>
                        </div>
                        <br />
                        <div class="row question danxuan" <?php if(($questionInfo['questionType'] && $questionInfo['questionType']==1) || empty($questionInfo['questionType']) ):?>style="display:block;"<?php else:?>style="display:none;"<?php endif;?>>
                            <div class="col-md-7">
                                题目：
                                <input class="form-control questionTitle" value="<?=$questionInfo['questionTitle']?>" type="text" placeholder="请输入题目">
                                <div class="horizontal-space"></div>
                            </div>
                            <div class="col-md-7">
                                选项：
                                <textarea rows="3" cols="200" class="form-control optionTitle" placeholder="每个选项已换行形式隔开"><?=$questionInfo['option']?></textarea>
                                <div class="horizontal-space"></div>
                            </div>
                            <div class="col-md-7">
                                答案：
                                <select class="answer">
                                    <option>请选择答案</option>
									<?php if($questionInfo):?><option selected="selected"<?php endif?> value="<?=$questionInfo['answerindex']?>"><?=$questionInfo['answerstr']?></option>
                                </select>
                                <div class="horizontal-space"></div>
                            </div>
                        </div>
                        <div class="row question tiankong" <?php if($questionInfo['questionType'] == 2):?>style="display:block;"<?php else:?>style="display:none;"<?php endif;?>>
                            <div class="col-md-7">
                                题目：
                                <input placeholder="请输入题目" value="<?=$questionInfo['questionTitle']?>" class="form-control questionTitle_tiankong" type="text" />
                                <div class="horizontal-space"></div>
                            </div>
                            <div class="col-md-7">
                                答案：
                                <textarea rows="3" cols="200" class="form-control tiankong_answer" placeholder="请填写所包含的词语"><?=$questionInfo['answer']?></textarea>
                                <div class="horizontal-space"></div>
                            </div>
                        </div>
                        <div class="row question xuantu" <?php if($questionInfo['questionType'] == 3):?>style="display:block;"<?php else:?>style="display:none;"<?php endif;?>>
                            <div class="col-md-7">
                                题目：
                                <input placeholder="请输入题目"  value="<?=$questionInfo['questionTitle']?>" class="form-control questionTitle_xuantu" type="text"  />
                                <div class="horizontal-space"></div>
                            </div>
                            <div class="col-md-7">
                            答案：
                                <div class='clearfix' style="margin-top:15px;">

                                    <div id="container" style="float: left">
                                        <a id="selectfiles" href="javascript:void(0);" class='btn'>选择图片</a>
                                        <a id="postfiles" href="javascript:void(0);" class='btn'>开始上传</a>
                                    </div>
                                    <span id="console"></span>
									<?php if($questionInfo['answer']):?>
									<span id = "ossfile"  style="position:relative;float:right;margin-left:5px;">
										<div class="bg_floating" style="float:right;margin-right:10px;">
											<img class="uploadpic" img-original='<?= $questionInfo['answer'] ?>' src="<?= OSSHOST.$questionInfo['answer'] ?>" width="120px" height="80px" alt="pic"/>
										</div>
									</span>
									<?php else :?>
                                    <span id="ossfile" style="position:relative;float:right;margin-left:5px">
                                    </span>
									<?php endif;?>
                                </div>
                            </div>
                        </div>
                        
                        <div class="horizontal-space"></div>
                        <div style="clear:both;">
                            <span id="js_submit" class="btn btn-default">提交</span>
                        </div>
                    </form>
                </div>
        </div>
        <input type="hidden" id="idpalce" value="<?php echo $AdInfo['id']?>" />
		<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>
<script src="<?= STATICURL; ?>js/jquery.min.js"></script>

<script src="<?php echo STATICURL; ?>js/bootstrap.min.js"></script>
<script src="<?php echo STATICURL; ?>layer/layer.js"></script>
<script type="text/javascript" src="<?=STATICURL;?>js/plupload-2.1.2/plupload.full.min.js"></script>
<script type="text/javascript" src="<?=STATICURL;?>js/latest.js"></script>
<script type="text/javascript" src="<?=STATICURL;?>js/ad-upload.js"></script>

<script>
    $(document).ready(function(){
        $(".questionType").on("change",function(){
            var type = $(this).val();
            if(type == 1)
            {
                $(".question").css("display","none");
                $(".danxuan").css("display","block");
                
            }else if(type == 2)
            {
                $(".question").css("display","none");
                $(".tiankong").css("display","block");
            }else if(type == 3)
            {
                $(".question").css("display","none");
                $(".xuantu").css("display","block");
            }
        });
		
		$(".single_question_point").bind({
                keyup:function(){
                     var txt = $('.single_question_point').val();
                     var reg = /^[\d]+$/;
                     if(!reg.test(txt) ){
                            $(this).val('');
                     }
                },
                focus:function(){
                    if ($(this).val() == 0){
                        $(this).val('');
                    }
                },
                blur:function(){
                    if ($(this).val() == ''){
                        $(this).val('');
                    }                   
                }
        });

        $(".optionTitle").bind({
                blur:function(){
                        var optionTitle = $(".optionTitle").val();
                        var strs= new Array(); //定义一数组
                        strs=optionTitle.split("\n"); //字符分割
                        var _option = "";
                        for (i=0;i<strs.length ;i++ )
                        {
							
                            if(strs[i]){
                                _option += "<option  value='"+(i+1)+"'>"+strs[i]+"</option>";
                            }
                        } 
                        $(".answer").html(_option);
                },

        });  

        $("#js_submit").on("click",function(){
            var newsID = "<?=$id?>";
			var questionID = "<?=$questionInfo['questionID']?>";
            var questionType = $(".questionType").val();
            var single_question_point = $(".single_question_point").val();
			var single_question_money = $(".single_question_money").val();
		
            if(questionType == 1)
            {
                var questionTitle = $(".questionTitle").val();
                
            }else if(questionType == 2)
            {
                var questionTitle = $(".questionTitle_tiankong").val();
            }else if(questionType == 3)
            {
                var questionTitle = $(".questionTitle_xuantu").val();
            }
            
            var answer = "";
            var optionTitle = "";
            if (questionType == ""){
                layer.msg("题目类型不能为空");
                return;
            }
            if (questionTitle == ""){
                layer.msg("题目标题不能为空");
                return;
            }
            if(questionType == 1)
            {
                //单选
                var optionTitle = $(".optionTitle").val();
                if (optionTitle == ""){
                    layer.msg("题目选项不能为空");
                    return;
                }
          
            }
            if(questionType == 1)
            {
               
                var answer = $(".answer").val();
                if (answer == ""){
                    layer.msg("填空答案不能为空");
                    return;
                }
            }
             if(questionType == 2)
            {
               
                var answer = $(".tiankong_answer").val();
                if (answer == ""){
                    layer.msg("填空答案不能为空");
                    return;
                }
            }
             if(questionType == 3)
            {
                var answer = $(".uploadpic").attr("img-original");
                if(answer == "" || answer == undefined){
                    layer.msg("选图答案不能为空");return false;   
                }
            }
            $.post("/luckydog/examination/do_editquestion", {questionID:questionID,single_question_point:single_question_point,single_question_money:single_question_money,newsID:newsID,questionType:questionType,questionTitle:questionTitle,answer:answer,optionTitle:optionTitle}, function(data) {
                if (data) {
                    console.log(data);
                    layer.msg("成功");
                    window.parent.location.reload();
                }else{
                    layer.msg("失败");
                }
            });
        });     
    });

</script>


